package org.grayrabbit.cms.plugin;

import org.grayrabbit.cms.plugin.DefaultModuleDescriptorFactory;
import org.grayrabbit.cms.plugin.ModuleDescriptor;
import org.grayrabbit.cms.plugin.PluginParseException;
import org.grayrabbit.cms.plugin.descriptors.PortletModuleDescriptor;
import org.grayrabbit.cms.util.CmsUtils;


public class CmsModuleDescriptorFactory extends DefaultModuleDescriptorFactory {
	public CmsModuleDescriptorFactory(){
		addModuleDescriptor("portlet", PortletModuleDescriptor.class);
	}
	
	public ModuleDescriptor getModuleDescriptor(String type)
		    throws PluginParseException, IllegalAccessException, InstantiationException, ClassNotFoundException
		  {
		    Class<? extends ModuleDescriptor> moduleDescriptorClazz = getModuleDescriptorClass(type);

		    if (moduleDescriptorClazz == null)
		    {
		      throw new PluginParseException("Cannot find ModuleDescriptor class for plugin of type '" + type + "'.");
		    }

		    return (ModuleDescriptor)CmsUtils.loadComponent(moduleDescriptorClazz);
		  }
}
